home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Dev / misc / temgen.lha / Temgen / tg-0.11 / util.c < prev    next >
C/C++ Source or Header  |  2004-06-11  |  855b  |  48 lines

  1. #include <string.h>
  2.  
  3. #include "strbuf.h"
  4.  
  5. const char *unquote( const char *s )
  6. {
  7.     static struct strbuf *buf = 0;
  8.     int len;
  9.     
  10.     if ( !s ) return 0;
  11.     if ( !s[0] ) return "";
  12.     if ( s[0] != '"' && s[0] != '\'' ) return s;
  13.     len = strlen( s );
  14.     
  15.     if ( buf ) 
  16.         sb_clear( buf );
  17.     else
  18.         buf = new_strbuf( len-1, 256 );
  19.  
  20.     sb_cat( buf, s+1, len-2 );
  21.     return sb_data( buf );
  22. }
  23.  
  24. const char *unescape( const char *s, int len )
  25. {
  26.     const char *c;
  27.     static struct strbuf *buf = 0;
  28.     
  29.     if ( !s ) return 0;
  30.     if ( !s[0] ) return "";
  31.  
  32.     if ( buf ) 
  33.         sb_clear( buf );
  34.     else
  35.         buf = new_strbuf( 256, 256 );
  36.  
  37.     for ( c=s; len>0 && *c; c++, len-- ) {
  38.         if ( *c=='\\' && len>1 ) {
  39.             c++;
  40.             len--;
  41.         }
  42.         sb_cat( buf, c, 1 );
  43.     }
  44.  
  45.     return sb_data( buf );
  46. }
  47.  
  48.